//
//  XJPayPasswordModifyController.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/5/24.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJPayPasswordModifyController.h"
#import "XJPayPasswordModifyView.h"
@interface XJPayPasswordModifyController ()
@property(nonatomic, strong) XJPayPasswordModifyView *paypwdModifyView;

@end

@implementation XJPayPasswordModifyController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navTitle = @"支付密码";
    
    [self.view addSubview:self.paypwdModifyView];
}

- (XJPayPasswordModifyView *)paypwdModifyView {
    if (!_paypwdModifyView) {
        _paypwdModifyView = [[XJPayPasswordModifyView alloc] initWithFrame:self.view.bounds];
        
        
        XJWeakSelf(self);
        // 回调事件
        _paypwdModifyView.payPasswordModifyViewClickButtonBlock = ^{
            [weakself bussinessLogicOfSureModifyButton];
        };
    }
    return _paypwdModifyView;
}

// 处理点击按钮的 业务逻辑
- (void)bussinessLogicOfSureModifyButton {
    
    //1.请输入6位数密码
    NSString *pwd = self.paypwdModifyView.ppPwdTextField.text;
    if ([NSString isEmptyString:pwd]) {
        [JRToast showWithText:@"请输入6位数密码"];
        return;
    }
    
    //1-2密码过短
    //1-3密码过长
    if (pwd.length < 6) {
        [JRToast showWithText:@"密码过短"];
        return;
    }
    
    if (pwd.length > 6) {
        [JRToast showWithText:@"密码过长"];
        return;
    }
    
    NSString *surePwd = self.paypwdModifyView.ppSurePwdTextField.text;
    
    //2.请输入确认密码
    if ([NSString isEmptyString:surePwd]) {
        [JRToast showWithText:@"请输入确认密码"];
        return;
    }
    
    //3.两次密码不一致
    if (![pwd isEqualToString:surePwd]) {
        [JRToast showWithText:@"两次密码不一致,请重新输入"];
        return;
    }
    
    //4.调接口
    
    [self requestModifyPayPasssword:pwd];
}


- (void)requestModifyPayPasssword:(NSString *)pwd {
    [XJHttpTool requestModifyPayPwd:pwd successH:^(id responseObjc) {
        XJLog(@"成功:%@",responseObjc);
        
        // 成功之后要干么?????
        
        
    } failH:^(NSError *error) {
        XJLog(@"失败:%@",error);
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
